<?php

/**
 * Forgotten password form.
 * 
 * @package disputeo
 * @version 1.0
 * @author jimmy.dixon
 */
class Application_Form_Reset extends Application_Form_Register
{

    /**
     * @var string 
     */
    protected $_legend = 'Enter the email address you signed up with.';

    /**
     * @var string
     */
    protected $_emailError = 'Sorry, we have no record of this account.';

    /**
     * Set form elements
     */
    public function init()
    {
        $this->setName('reset');
        $this->setAction('/login/reset');
        $this->_addEmailElement();
        $this->addCaptcha();
        $this->_setDisplayGroup();
        $this->_addDisplayGroup('resetGroup', $this->_legend);
        $this->_addSubmitElement('Email Me');
        $this->_addValidators();
    }

    /**
     * Setup form element validation
     */
    protected function _addValidators()
    {
        $notEmpty = new Zend_Validate_NotEmpty();
        $notEmpty->setMessage($this->_emailError, Zend_Validate_NotEmpty::IS_EMPTY);
        $dbcheck = new Zend_Validate_Db_RecordExists(
                array('table' => 'users', 'field' => 'email'));
        $dbcheck->setMessage($this->_emailError, Zend_Validate_Db_RecordExists::ERROR_NO_RECORD_FOUND);
        $this->getElement('email')->addValidators(array($notEmpty, $dbcheck));
    }
    
    /**
     * Set fieldset arrangement
     */
    protected function _setDisplayGroup()
    {
        $this->_displayGroup = array(
            'email', 'captcha'
        );
    }

}